package com.zhentao.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.model.common.buiness.dto.BuOrderStatusDto;
import com.zhentao.model.common.buiness.pojo.Orders;
import com.zhentao.model.common.buiness.vo.BuOrderFindAllVO;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.model.common.enums.AppHttpCodeEnum;
import com.zhentao.service.BuOrdersService;
import com.zhentao.mapper.BuOrdersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 薄超轩
* @description 针对表【orders】的数据库操作Service实现
* @createDate 2024-09-18 16:56:04
*/
@Service
public class BuOrdersServiceImpl extends ServiceImpl<BuOrdersMapper, Orders>
    implements BuOrdersService {
@Autowired
private BuOrdersMapper buOrdersMapper;

    /**
     * 商家端：订单查询所有
     * @param vo
     * @return
     */
    @Override
    public ResponseResult findAll(BuOrderFindAllVO vo) {
        List<BuOrderFindAllVO> orderFindAllVOS=buOrdersMapper.findAll(vo);
        return ResponseResult.okResult(orderFindAllVOS);
    }

    /**
     * 商家端：修改订单状态
     * @param dto
     * @return
     */
    @Override
    public ResponseResult orderStatus(BuOrderStatusDto dto) {
        if (dto==null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        Orders orders = buOrdersMapper.selectById(dto.getId());
        if (orders==null){
            return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
        }
        orders.setStatus(dto.getStatus());
        buOrdersMapper.updateById(orders);
        return ResponseResult.okResult("修改成功");
    }
}




